package com.zzyl.controller;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.utils.ObjectUtil;
import com.zzyl.vo.ContractVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Slf4j
@Api(tags = "服务项目管理相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    //分页条件查询服务项目
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(
            @ApiParam(value = "护理项目名称")  String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("分页查询护理计划列表：name={}, status={}, pageNum={}, pageSize={}", name, status, pageNum, pageSize);
        PageResponse<NursingProjectVo> pageInfo = nursingProjectService.selectByPage(pageNum, pageSize, name, status);
        return success(pageInfo);
    }

    //新增护理项目
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(@ApiParam(value = "护理项目信息") @RequestBody NursingProjectDto nursingProjectDto){
        log.info("新增护理项目：{}", nursingProjectDto);
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理项目")
    public ResponseResult<NursingProjectVo> getNursingProjectById(@ApiParam(value = "护理项目ID") @PathVariable Long id){
        log.info("根据ID查询护理项目：{}", id);
        NursingProjectVo nursingProjectVo = nursingProjectService.getNursingProjectById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult updateNursingProject(@ApiParam(value = "护理项目信息") @RequestBody NursingProjectDto nursingProjectDto){
        log.info("修改护理项目：{}", nursingProjectDto);
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理项目状态")
    public ResponseResult updateNursingProjectStatus(@ApiParam(value = "护理项目ID") @PathVariable Long id,
                                                     @ApiParam(value = "状态：0-禁用，1-启用") @PathVariable Integer status){
        log.info("修改护理项目状态：id={}, status={}", id, status);
        nursingProjectService.updateNursingProjectStatus(id,status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteNursingProject(@ApiParam(value = "护理项目ID") @PathVariable Long id){
        log.info("删除护理项目：{}", id);
        nursingProjectService.deleteNursingProject(id);
        return success();
    }


    @GetMapping("/all")
    @ApiOperation("查询全部护理项目")
    public ResponseResult<List<NursingProjectVo>> getAllNursingProject(){
        log.info("查询全部护理项目");
        List<NursingProjectVo> nursingProjectVo = nursingProjectService.getAllNursingProject();
        return success(nursingProjectVo);
    }


}